/*
 * LiquidBounce Hacked Client
 * A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
 * https://github.com/CCBlueX/LiquidBounce/
 */
package net.ccbluex.liquidbounce.features.module.modules.exploit;

import net.ccbluex.liquidbounce.event.EventTarget;
import net.ccbluex.liquidbounce.event.PacketEvent;
import net.ccbluex.liquidbounce.features.module.Module;
import net.ccbluex.liquidbounce.features.module.ModuleCategory;
import net.ccbluex.liquidbounce.features.module.ModuleInfo;
import net.minecraft.network.play.client.C01PacketChatMessage;

@ModuleInfo(name = "ForceUnicodeChat", description = "Allows you to send unicode messages in chat.", category = ModuleCategory.EXPLOIT)
public class ForceUnicodeChat extends Module {
    @EventTarget
    public void onPacket(final PacketEvent event) {
        if(event.getPacket() instanceof C01PacketChatMessage) {
            final C01PacketChatMessage chatMessage = (C01PacketChatMessage) event.getPacket();

            final String message = chatMessage.getMessage();
            final StringBuilder stringBuilder = new StringBuilder();

            for(char c : message.toCharArray())
                if(c >= 33 && c <= 128)
                    stringBuilder.append(Character.toChars(c + 65248));
                else
                    stringBuilder.append(c);

            chatMessage.message = stringBuilder.toString();
        }
    }
}
